﻿#ifndef __REDIS_CLIENT_HEAD__
#define __REDIS_CLIENT_HEAD__

#include <mongoc.h>
#include <string>
#include <memory>
#include <vector>

#include "multi_task/task.h"
#include "redis_query_result.h"

//wrap class for redis-c-driver api

struct redisContext;

class CRedisDbConnection
{
public:
	CRedisDbConnection();
	~CRedisDbConnection();
	bool Connect(const std::string & host
		, const std::string & port_or_socket
		, const std::string & user
		, const std::string & password
		, const std::string & database);

	//Query
	RedisQueryResultSptr Query(const std::string& commandstring);


	//Query
	RedisQueryResultSptr Query(const std::string& commandstring, const std::string&  param1);

	RedisQueryResultSptr Query(const char *format, ...);


	void	KeepAlive(int iS);
	void	Ping();

	redisContext * GetRedisContext()
	{
		return m_pRedisContext;
	}
private:
	redisContext    * m_pRedisContext;

	bool			  m_bConnected;
	time_t			  m_iLastActiveTime;
};

////----------------------------------------------------------------------------------------
//// contains a single async query
//// 单个异步查询操作
//class REDIS_DBLIB_API RedisQuery : public RedisOperation
//{
//public:
//	RedisQuery(const char *rediscommand, IRedisQueryCallback * callback, RedisAsyQueryResultQueue * queue)
//		: _rediscommand(rediscommand), m_callback(callback), m_queue(queue) {}
//	~RedisQuery() {}
//	void Execute(RedisDBConnection *con);
//
//protected:
//
//
//private:
//	Cactus::String						_rediscommand;
//	IRedisQueryCallback*				m_callback;
//	RedisAsyQueryResultQueue*			m_queue;
//};

#endif
